import os.path as osp
from time import strftime, localtime
from lib.utils.get_config import get_cfg
from lib.datasets.dataset import GraphDatasetLoader
from lib.optimizers.base.swarm import Swarm

# read config file
cfg = get_cfg(osp.join(osp.abspath("./"), 'configs/config.yaml'))


def main(exp_name='Cora'):
    print(f'-----Current Experiment: {exp_name}-----')
    experimenter = GraphDatasetLoader(root=osp.join(
        cfg['ROOT'], cfg['DATA_DIR']), name=exp_name)
    print(experimenter.__summary__())
    opt = Swarm(informants_number=cfg['NUM_INFORMANTS'],
                particle_number=cfg['NUM_PARTICLES'])
    res_df = opt.run(dataset=experimenter.dataset, task=experimenter.task)
    res_df.to_csv(osp.join(
        cfg['LOGS_DIR'], f'{exp_name}_{strftime("%Y-%m-%d_%H-%M", localtime())}.csv'))
    return res_df
